package com.atguigu.gmall.gateway.filter;

import com.netflix.client.config.IClientConfigKey;
import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
import lombok.Data;
import lombok.Value;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: 86182
 * @Date: 2021/8/18
 * @Time: 18:31
 * @Version:
 */
@Component
public class XxxGatewayFilterFactory extends AbstractGatewayFilterFactory<XxxGatewayFilterFactory.KeyValueConfig> {

    public XxxGatewayFilterFactory(){
        super(KeyValueConfig.class);
    }

    @Override
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("keys");
    }

    @Override
    public ShortcutType shortcutType() {
        return ShortcutType.GATHER_LIST;
    }

    @Override
    public GatewayFilter apply(KeyValueConfig config) {
        //实现GatewayFilter接口
        return new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                System.out.println("自定义过滤器! key = " + config.keys);
                return chain.filter(exchange);
            }
        };
    }
    @Data
    public static class KeyValueConfig{
        private List<String> keys;

    }
}
